<?php

namespace app\index\controller;

use app\index\model\Banner as BannerModel;
use think\Controller;
use think\Request;
use app\index\model\News as NewsModel;

class News extends BaseController
{
    public function __construct(Request $request = null)
    {
        parent::__construct($request);
        $banner = BannerModel::getBanner('news');
        $action = $request->action();
        $this->assign('banner', $banner);
        $this->assign('action', $action);
    }

    public function index()
    {
        $news = NewsModel::getNews();
        $this->paginate($news->lastPage(), $news->currentPage());
        $this->assign('news', $news);
        return $this->fetch();
    }

    public function detail($id = 0)
    {
        $news = NewsModel::getById($id);
        $preId = NewsModel::getPreId($id);
        $nextId = NewsModel::getNextId($id);
        $this->assign('preId', $preId);
        $this->assign('nextId', $nextId);
        $this->assign('news', $news);
        return $this->fetch();
    }




}
